package cn.edu.zju.ccnt.mashup.gui;

import javax.swing.SwingUtilities;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

import cn.edu.zju.ccnt.mashup.jena.RDFReader;
import cn.edu.zju.ccnt.mashup.jung.RDFViz;
import org.eclipse.swt.layout.FillLayout;

public class RDFGraphViewer extends ViewPart {

	public static final String ID = "cn.edu.zju.ccnt.mashup.gui.RDFGraphViewer"; //$NON-NLS-1$
	
	private Composite composite;
	private java.awt.Frame frame;
	private RDFViz rdfViz;

	public Composite getComposite() {
		return composite;
	}
	
	public java.awt.Frame getFrame() {
		return frame;
	}

	public RDFViz getRdfViz() {
		return rdfViz;
	}

	public void setRdfViz(RDFViz rdfViz) {
		this.rdfViz = rdfViz;
	}

	public RDFGraphViewer() {
	}

	/**
	 * Create contents of the view part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		
		composite = new Composite(parent, SWT.EMBEDDED);
		composite.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		frame = SWT_AWT.new_Frame(composite);   

		SwingUtilities.invokeLater(new Runnable() {   
		      public void run() {
		    	  createYourSwingComponents(frame);
		      }   
		}); 

		createActions();
		initializeToolBar();
		initializeMenu();
	}
	
	private void createYourSwingComponents(java.awt.Frame frame) {   
		rdfViz = new RDFViz("data/rdf_sample.rdf");
		rdfViz.showRDFGraph();
		rdfViz.addInteract();
		frame.add(rdfViz);
		frame.pack();
		frame.setVisible(true);
	}  

	/**
	 * Create the actions.
	 */
	private void createActions() {
		// Create the actions
	}

	/**
	 * Initialize the toolbar.
	 */
	private void initializeToolBar() {
		IToolBarManager toolbarManager = getViewSite().getActionBars()
				.getToolBarManager();
	}

	/**
	 * Initialize the menu.
	 */
	private void initializeMenu() {
		IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
	}

	@Override
	public void setFocus() {
		// Set the focus
	}
	
	
}
